-- MonsterDisplayM
-- Create by chendh
-- 怪物动作控制模块

module("MonsterDisplayM", package.seeall);

-- 所有的配置信息
local monsterDisplayTable = {};

-- 载入配置表
local _init = false;
local loadCsv = function()
    if _init then return end
    _init = true;

    monsterDisplayTable = {};

    -- 转换下audio信息表
    local display_CSV = get_monster_skill_display_CSV();
    for i = 1, #display_CSV do
        local data = display_CSV[i];

        if not monsterDisplayTable[data.class_id] then
            monsterDisplayTable[data.class_id] = {};
        end

        monsterDisplayTable[data.class_id][data.skill_id] = parseData(data);
    end

    display_CSV = {};
end

-- 模块初始化
function init()
    loadCsv();
end

-- 解析数据
function parseData(info)
    local range = info["attack_frame"];
    if not string.startWith(range, "[") or not string.endWith(range, "]") then
        error(string.format("字段(%s)配置格式错误!", tostring(field)));
        return info;
    end

    local arr = string.explode(string.sub(range, 2, -2),",");
    if #arr ~= 2 then
        error(string.format("字段(%s)配置格式错误!", tostring(field)));
        return info;
    end

    info["attack_frame"] = { tonumber(arr[1]), tonumber(arr[2]) };

    return info;
end

-- 检索怪物技能动画信息
function getMonsterSkillDisplay(classId, skillId)
    local m = monsterDisplayTable[classId];

    if not m or not m[skillId] then
        return {};
    end

    return m[skillId];
end
